package com.swak.consistency.reliablemsg.transport.impls;

import com.swak.annotation.QueueTypes;
import com.swak.consistency.reliablemsg.context.ReliableMsgLog;
import com.swak.consistency.reliablemsg.transport.ReliableMsgLogTransport;
import com.swak.rabbit.EventBus;
import com.swak.utils.StringUtils;

public class RabbitmqReliableMsgLogTransport implements ReliableMsgLogTransport {

	@Override
	public boolean support(ReliableMsgLog reliableMsg) {
		return StringUtils.isBlank(reliableMsg.getQueueType())
				|| QueueTypes.Rabbit.name().equals(reliableMsg.getQueueType());
	}

	@Override
	public void send(ReliableMsgLog reliableMsg) {
		String routingKey = StringUtils.defaultIfBlank(reliableMsg.getFilter(), reliableMsg.getQueue());
		EventBus.me().post(reliableMsg.getQueue(), routingKey, reliableMsg.getMessage());
	}
}
